package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.OrderDetailDto;
import com.qs.pojo.dto.OrderDto;
import com.qs.pojo.entity.OrderInfo;
import com.qs.pojo.vo.OrderInfoVo;
import com.qs.pojo.vo.YearOrderVo;
import com.qs.response.Response;
import com.qs.response.ResponseEnum;
import com.qs.service.IOrderInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单信息表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-12-07
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/order/info")
@RequiredArgsConstructor
public class OrderInfoController {

    private final IOrderInfoService orderInfoService;

    /**
     * 保存订单数据
     * @param orderDto
     * @return
     */
    @PostMapping("/save/{orderId}/{userId}")
    public Response saveOrderInfo(@RequestBody OrderDto orderDto,
                                  @PathVariable("orderId") String orderId,
                                  @PathVariable("userId") Integer userId){
        log.info("保存订单数据请求进来-----------");
        Response response = orderInfoService.saveOrderInfo(orderDto, orderId, userId);
        return response;
    }

    /**
     * 获取当前用户的年总消费
     * @param userId
     * @return
     */
    @GetMapping("/year/spend/{userId}")
    public Response getYearData(@PathVariable("userId") Integer userId){
        log.info("获取当前用户的年总消费请求进来-----------");
        List<YearOrderVo> yearData = orderInfoService.getYearData(userId);
        return Response.success(yearData);
    }

    /**
     * 获取当前用户的本周消费
     * @param userId
     * @return
     */
    @GetMapping("/week/spend/{userId}")
    public Response getWeekdayData(@PathVariable("userId") Integer userId){
        log.info("获取当前用户的本周消费请求进来-----------");
        List<Float> weekdayData = orderInfoService.findWeekdayData(userId);
        return Response.success(weekdayData);
    }

    /**
     * 获取当前用户的年总消费
     * @param userId
     * @return
     */
    @GetMapping("/year/spend/total/{userId}")
    public Response getYearTotalData(@PathVariable("userId") Integer userId){
        log.info("获取当前用户的年总消费请求进来-----------");
        float total = orderInfoService.getYearTotalData(userId);
        return Response.success(total);
    }
}
